Todo.Model.Category = Backbone.Model.extend({

    // Default attributes for the todo category.
    defaults  : function () {
        return {
            id      : Todo.categories ? Todo.categories.generateNewId() : _.uniqueId('new_'),
            name    : 'Новый элемент',
            deleted : false,
            position: Todo.categories ? Todo.categories.nextOrder() : 1
        }
    },

    // Ensure that each todo created has all fields
    initialize: function () {
        if (Todo.debug) {
            console.log('Todo.Model.Category::initialize');
        }

        if (!this.get("name")) {
            this.set({
                "name": this.defaults().title
            });
        }

        this.on('updateItems', this.updateItems, this);

        this.trigger('updateItems');
    },

    updateItems: function () {
        this.set('items', Todo.items.getByCategory(this.get('id')));
    },

    // Toggle the `done` state of this todo item.
    toggle     : function () {
        if (Todo.debug) {
            console.log('Todo.Model.Category::toggle');
        }

        this.save({done: !this.get("done")});
    }
});